//
//  PlanPeopleNewVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/5/2.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "PlanPeopleNewVC.h"
#import "PlanPeopleHeadView.h"
#import "PlanVM.h"
#import "MyVM.h"
#import "UserInfoModel.h"
#import "LabCell.h"
#import "GradesModel.h"
#import "PlanPeopleNewCell.h"
#import "CommentVM.h"
#import "CommentsCell.h"
#import "OtherInfoVC.h"
#import "ExceptionalVC.h"
#import "OnlineTop_up.h"
@interface PlanPeopleNewVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) UserInfoModel *userModel;
@property (nonatomic ,strong) PlanPeopleHeadView  *headView;
@property (nonatomic ,strong) NSMutableArray *dataArr;
@end

@implementation PlanPeopleNewVC{
    NSInteger   selectRow;
    NSString    *selectModelId;
    NSMutableArray *commentsImages;
    NSString       *sendStr;
    QXLable         *labCount;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (!_betModel) {
        [self getData];
    }
    
    [self.tableView reloadData];
    // Do any additional setup after loading the view.
}

- (void)backClick{
    [super backClick];
    [self.headView cancleTimer];
}

- (void)getData{
//    WS(weakSelf);
//    [[PlanVM manage] getLastPlayWithUid:self.model.UserId andLType:[self.lotteryModel.lType integerValue] andPlayName:self.playName andPaytype:self.payType Success:^(id returnValue) {
//        weakSelf.betModel=[BetModel mj_objectWithKeyValues:returnValue];
//        [weakSelf.tableView reloadData];
//    } andFail:^(NSString *errorMessage, NSError *error) {
//        if ([errorMessage intValue]==60018) {
//            UIAlertController *alertCtrl=[UIAlertController alertControllerWithTitle:nil message:@"金币不足" preferredStyle:UIAlertControllerStyleAlert];
//            UIAlertAction *cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];;
//            UIAlertAction *goAction=[UIAlertAction actionWithTitle:@"前往充值" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                OnlineTop_up *vc=[[OnlineTop_up alloc]init];
//                [weakSelf.navigationController pushViewController:vc animated:YES];
//            }];
//            [alertCtrl addAction:cancleAction];
//            [alertCtrl addAction:goAction];
//            [weakSelf presentViewController:alertCtrl animated:YES completion:nil];
//        }
//    }];
}

#pragma mark -- 打赏
- (void)exceptional{
    ExceptionalVC *vc=[[ExceptionalVC alloc]init];
    vc.model=self.model;
    vc.lotteryModel=self.lotteryModel;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.betModel?2:0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5)];
    view.backgroundColor=DEFAULTBGCOLOR;
    return view;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        PlanPeopleNewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"PlanPeopleNewCell" forIndexPath:indexPath];
        cell.labTitle.text=[NSString stringWithFormat:@"%@期",self.betModel.Issue];
        cell.labContent.text=@"未开奖";
        cell.labContent.textColor=NAVCOLOR;
        return cell;
    }else{
        PlanPeopleNewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"PlanPeopleNewCell" forIndexPath:indexPath];
        cell.labTitle.text=self.betModel.PlayName;
        cell.labContent.text=self.betModel.BetNum;
        cell.labContent.textColor=DEFAULTTEXTBLACKCOLOR;
        cell.contentView.backgroundColor=DEFAULTBGCOLOR;
        return cell;
    }
    
}

#pragma mark -- 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        [_tableView registerClass:[PlanPeopleNewCell class] forCellReuseIdentifier:@"PlanPeopleNewCell"];
        _tableView.rowHeight=UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight=50;
        _tableView.backgroundColor=[UIColor whiteColor];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(weakSelf.view);
            make.top.equalTo(self.headView.mas_bottom);
        }];
    }
    return _tableView;
}

- (PlanPeopleHeadView *)headView{
    if (!_headView) {
        WS(weakSelf);
        _headView=[[PlanPeopleHeadView alloc]init];
        _headView.userId=self.model.UserId;
        _headView.lType=self.lotteryModel.lType;
        _headView.clickExceptional = ^{
            [weakSelf exceptional];
        };
        [self.view addSubview:_headView];
        [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.view);
            make.height.mas_equalTo(@(real_size(75)));
        }];
    }
    return _headView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
